/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * UserPreferenceShow.java
 *
 * Created on Feb 28, 2012, 5:58:46 PM
 */

package UserInterface;

import AI.PlaceRoute;
import AI.UserPlanOut;
import AI.UserPreference;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author Harsha
 */
public class UserPreferenceShow extends javax.swing.JFrame {
private UserPreference preference;
    /** Creates new form UserPreferenceShow */
    public UserPreferenceShow(UserPreference preference) {
        this.preference=preference;
        initComponents();
        setLocationRelativeTo(this);
        setVisible(true);
        
        setJTextArea();

    }
    public void setJTextArea()
    {
        jTextArea1.append("Place Details\n");
        for(int i=0;i<preference.getData().size();i++)
        {
            for(int j=0;j<preference.getData().get(i).getLocations().size();j++)
            {
             jTextArea1.append(preference.getData().get(i).getLocations().get(j)+"-"+preference.getData().get(i).getCityName()+"\n");
            }
        }
        jTextArea1.append("\n");
        jTextArea1.append("Journey Details\n");
        jTextArea1.append("Journey Days:"+Integer.toString(preference.getNoOfDays())+"\n");
        jTextArea1.append("Journey LeavingTime:"+Double.toString(preference.getStartTime())+"AM\n");
        jTextArea1.append("Journey ArrivalTime:"+Double.toString(preference.getArrivalTime()-12)+"PM\n");
        jTextArea1.append("\n");
        jTextArea1.append("Meal Preferences\n");
        if(preference.isBreakFast())
        {
             jTextArea1.append("Breakfirst at a meal place around: "+Double.toString(preference.getBreakFirstTime())+"AM\n");
        }
        else
        {
            jTextArea1.append("Breakfirst is on the journey around: "+Double.toString(preference.getBreakFirstTime())+"AM\n");
        }
        jTextArea1.append("Lunch is around around: "+Double.toString(preference.getLunchTime()-12)+"PM\n");
        if(preference.isEveningMeal())
        {
             jTextArea1.append("Evening tea at a meal place around: "+Double.toString(preference.getEveningMealTime()-12)+"PM\n");
        }
        else
        {
            jTextArea1.append("Evening tea is on the journeyaround: "+Double.toString(preference.getEveningMealTime()-12)+"PM\n");
        }
        jTextArea1.append("Dinner is around: "+Double.toString(preference.getDinnerTime())+"PM\n");

    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jButton1.setText("Show Plan");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton1)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 552, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(54, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      PlaceRoute place=new PlaceRoute(preference);
      System.out.println("noh"+preference.getSelectedCityId().size());
      ArrayList<Integer> ii=preference.getSelectedCityId();
      for(int i=0;i<ii.size();i++)
      {
          System.out.println(ii.get(i));
      }
      UserPlanOut plan=place.planRoute(preference);
      if(plan.isIsPossible())
      {
      PlanOut planOut=new PlanOut(plan);
       }
        else
      {
          JOptionPane.showMessageDialog(new JFrame(), "Trip is not possible withing given contraints");
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new UserPreferenceShow(null).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables

}
